home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / tess / tess-1.0 / aGroup.pswm-newnew < prev    next >
Encoding:
Text File  |  1992-06-30  |  5.8 KB  |  290 lines

  1. #import "aGroup.h"
  2. #import "aGroup-inter.h"
  3. #import "TessSketch.h"
  4. #import "Underlay.h"
  5. #import "GeneratorOverlay.h"
  6.  
  7. @implementation aGroup
  8.  
  9. +new 
  10. {
  11.   self = [super new];
  12.   [self setScaling: 1.0 : 1.0];
  13.   [self setAutosizing: NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
  14.   return self;
  15. }
  16.  
  17. + setup
  18. {
  19.   GroupSetup();                    // call only once
  20.   return self;
  21. }
  22.  
  23. - drawSelf:(const NXRect *)rects :(int)rectCount
  24. {
  25.   [self clip: GENOFFT : GENOFFT ];
  26.   [[genovly getImage]  composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
  27.   return self;
  28. }
  29.  
  30. - setGenovly: sender
  31. {
  32.   genovly = sender;
  33.   return self;
  34. }
  35.     
  36. - performTesselation: sender
  37. {
  38.   id imgview,outview,outimg;
  39.   NXPoint pt,genofft;
  40.   NXSize lsize;
  41.   NXRect outrect;
  42.   float xstart;
  43.   int xlimit,ylimit;
  44.   
  45.   outview = [sender getOutputView];
  46.   outimg = [outview getImage];
  47.   [self getLatticeUnitSize: &lsize];
  48.   [sender getImageView:&imgview withOffset: &genofft];
  49.   if(![outimg lockFocus]) fprintf(stderr,"Couldn't lock outimg focus\n");
  50.   PSgsave();
  51.   PSscale(xscaling,yscaling);
  52.   [outview getFrame: &outrect];
  53. #ifdef DEBUG
  54.   fprintf(stderr,"Output rect: %f,%f,%f,%f\n",outrect.origin.x,outrect.origin.y,
  55.       outrect.size.height,outrect.size.width);
  56. #endif
  57.   
  58.   pt.x = pt.y = 0.0;
  59.   ylimit = (int)(outrect.size.height/lsize.height) + 2;
  60.   do {
  61.     PSmoveto(0.0,0.0);
  62.     if(ylimit%2){
  63.       pt.x -= lsize.width;        /* adjust back for rhombic & poly case*/
  64.     } 
  65.     xlimit = (int)(outrect.size.width/lsize.width) + 4;
  66.     xstart = pt.x;
  67.     do{
  68. #ifdef 0
  69.       fprintf(stderr,"Current point %f,%f: xlimit %d\n",pt.x,pt.y,xlimit);
  70. #endif
  71.       PSgsave();
  72.       PStranslate(pt.x,pt.y);
  73.       [self makeLatticeUnitAt: &genofft fromImage: [imgview getImage]];
  74.       PSgrestore();
  75.       [self rightTranslatePoint: &pt];
  76.     } while (xlimit--);
  77.     pt.x = xstart;
  78.     [self upTranslatePoint: &pt];
  79.   } while (ylimit--);
  80.   PSgrestore();
  81.   [outimg unlockFocus];
  82.   return self;
  83. }
  84.  
  85. - generator: (NXCoord) x : (NXCoord) y
  86. {
  87.   [self clip: x : y];
  88.   PSstroke();
  89.   return self;
  90. }
  91.  
  92. - clip: (NXCoord) x: (NXCoord) y
  93. {
  94.   return self;
  95. }
  96. - (BOOL) isRigidLattice
  97. {
  98.   return YES;
  99. }
  100. - rightTranslatePoint: (NXPoint *) pt
  101. {
  102.   return self;
  103. }
  104.  
  105. - upTranslatePoint: (NXPoint *)pt
  106. {
  107.   return self;
  108. }
  109.  
  110. - (NXSize *)getLatticeUnitSize: (NXSize *) size
  111. {
  112.   size->width = latticesize.width;
  113.   size->height = latticesize.height;
  114.   return &latticesize;
  115. }
  116.  
  117. - setScaling: (float) xscale:(float) yscale
  118. {
  119.   xscaling = xscale;
  120.   yscaling = yscale;
  121.   return self;
  122. }
  123.  
  124. - (float) xscaling
  125.   return xscaling; 
  126. }
  127. - (float) yscaling
  128.   return yscaling; 
  129. }
  130. - drawImage
  131. {
  132.   [self sketchTemplate];
  133.   return self;
  134. }
  135. - sketchTemplate
  136. {
  137.   return self;
  138. }
  139. - makeLatticeUnitAt: (NXPoint *) point fromImage: srcimg 
  140. {
  141.   return self;
  142. }
  143. - (NXPoint *)getGeneratorOffset: (NXPoint *) pt
  144. {
  145.   pt->x = pt->y = 0.0;
  146.   return pt;
  147. }
  148.  
  149. - (NXSize *)getGeneratorSize: (NXSize *) size
  150. {
  151.   size->width = size->height = 0.0;
  152.   return size;
  153. }
  154.  
  155. @end
  156.  
  157. int genfun () {  return 1; }
  158. int clipper () { return 1; }
  159. int tesselate () { return 1;}
  160.  
  161. defineps GroupSetup()
  162.    /groupsdict 40 dict def
  163.    groupsdict begin
  164.        /equi { 3 sqrt mul 2 div } bind def
  165.        /generatorcolor {0.655171 0.102771 0.629475 setrgbcolor } bind def
  166.        /glidecolor {0.373226 0.462386 0.528733 setrgbcolor } bind def
  167.        /reflectioncolor {0.333338 0.039216 0.237907 setrgbcolor } bind def
  168.        /translationcolor {1 0.054903 0.101962 setrgbcolor       } bind def
  169.        /anglecolor { 0 0 1 setrgbcolor } bind def
  170.        /latticeunitcolor { 0.5 setgray } bind def
  171.        /scaling 1.0 def    
  172.  
  173.        /arrow { % angle x y
  174.        newpath moveto dup rotate 
  175.        -13 6 rlineto 4 -6 rlineto 
  176.        -4 -6 rlineto closepath gsave 0 
  177.        setlinejoin stroke grestore fill neg rotate
  178.        } def
  179.  
  180.        /addpoints { % x y x y
  181.           exch % x y y x
  182.           4 1 roll %  y y x x
  183.           add 3 1 roll % x y y
  184.           add % x y
  185.     } bind def
  186.  
  187.        /duptop2 { % x y -> x y x y
  188.        dup     %  x y y
  189.        3 2 roll % y y x
  190.        dup % y y x x    
  191.        4 1 roll % x y y x
  192.        exch % x y x y    
  193.        } bind def
  194.  
  195.        /even { % num
  196.        cvi 1 and 1 eq not
  197.        } bind def
  198.  
  199.        /setscaling { % scale - wrap with dictionary use !!!
  200. %       groupsdict begin       
  201. %           /scaling exch def    
  202. %           [scaling 0 0 scaling 0 0] setmatrix
  203. %       end           
  204.     pop
  205.        } bind def
  206.  
  207.        /reflect { % angle
  208.        dup rotate  
  209.        [1 0 0 -1 0 0] concat 
  210.        neg rotate     
  211.        }     bind def
  212.  
  213.        /rhombus { % x y 
  214.        groupsdict begin    
  215.            moveto
  216.            latticeunitcolor
  217.            lattice:side 0 lineto
  218.            lattice:w lattice:h rlineto
  219.            lattice:side neg 0 rlineto
  220.            closepath
  221.            stroke
  222.        end        
  223.        } bind def
  224.  
  225.        /transv0 { %x y len
  226.        groupsdict begin
  227.            gsave    
  228.            2 setlinewidth
  229.            translationcolor    
  230.            moveto dup 0 rlineto stroke    
  231.            0 exch 0 arrow
  232.            grestore    
  233.        end        
  234.        } bind def
  235.  
  236.        /transv90 { %x y len
  237.        groupsdict begin
  238.            gsave 
  239.            2 setlinewidth
  240.            translationcolor    
  241.            moveto dup 0 exch rlineto stroke    
  242.            90 exch 0 exch arrow
  243.            grestore    
  244.        } bind def
  245.  
  246.        /transv60 { %x y run rise
  247.        groupsdict begin
  248.            gsave 
  249.            2 setlinewidth
  250.            translationcolor    
  251.            moveto 
  252.            duptop2    
  253.            rlineto stroke    
  254.            60 3 1 roll % angle of arrow
  255.            arrow
  256.            grestore    
  257.        end        
  258.        } bind def
  259.  
  260.        /reflectionaxis { % x1 y1 x2 y2
  261.        groupsdict begin    
  262.            reflectioncolor
  263.            moveto rlineto stroke    
  264.        end
  265.        } bind def
  266.  
  267.        /rotation3 { % size x y
  268.        groupsdict begin    
  269.            moveto    
  270.            /r3size exch def
  271.            /r3ext r3size equi def    
  272.            anglecolor
  273.            0 r3ext 2 div rmoveto
  274.            r3size 2 div r3ext neg rlineto
  275.            r3size neg 0 rlineto
  276.            closepath 
  277.            gsave fill grestore stroke
  278.        end
  279.        } bind def
  280.    end
  281. endps
  282.  
  283. defineps reflect(float angle)
  284.      groupsdict begin
  285.          angle reflect
  286.      end 
  287. endps
  288.